package com.beiye.drivertransport.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.bean.HoleCourseBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by ky on 2018/5/10.
 */


public class HoleCourseApt extends CommonAdapter<HoleCourseBean.RowsBean> {
    private final List<HoleCourseBean.RowsBean> mList;
    private Context context;
    private String begin;
    private String end;

    public HoleCourseApt(Context context, List<HoleCourseBean.RowsBean> mList, int itemLayoutId) {
        super(context, mList, itemLayoutId);
        this.context = context;
        this.mList = mList;
    }



    @Override
    public void convert(ViewHolder holder, HoleCourseBean.RowsBean item, final int position) {
        TextView tv_date = holder.getView(R.id.tv_hole3);//隐患日期上面
        ImageView img_num = holder.getView(R.id.img_num);//整改次数
        TextView tv_check = holder.getView(R.id.tv_check);//查看
        TextView tv_title = holder.getView(R.id.tv_title);//项目种类
        TextView tv_title2 = holder.getView(R.id.tv_title2);//检查项目
        TextView tv_title6 = holder.getView(R.id.tv_title6);//整改情况
        TextView tv_title7 = holder.getView(R.id.tv_title7);//审核情况
        ImageView img_middle = holder.getView(R.id.img_middle);//整改进度球
        ImageView img_endline = holder.getView(R.id.img_endline);//审核进度线
        ImageView img_end = holder.getView(R.id.img_end);//审核进度球
        TextView tv_time = holder.getView(R.id.tv_time);//隐患日期下面
        TextView tv_time1 = holder.getView(R.id.tv_time1);//整改日期
        TextView tv_time2 = holder.getView(R.id.tv_time2);//审核日期

        String examItem = mList.get(position).getExamItem();//检查项
        String examItemType = mList.get(position).getExamItemType();//项目种类
        long lSubmitDate = mList.get(position).getLSubmitDate();//隐患提交日期
        int reformNo = mList.get(position).getReformNo();//整改次数
        int lastRMark = mList.get(position).getLastRMark();//最近整改标记0待整改 1整改
        long lastRDate = mList.get(position).getLastRDate();//最近整改日期
        int lastCMark = mList.get(position).getLastCMark();//最近审核标记0待审核1审核2审核不通过
        long lastCDate = mList.get(position).getLastCDate();//最近审核日期

        if(examItemType==null)
        {
            tv_title.setText("");
        }else{
            tv_title.setText(examItemType);
        }
        if(examItem==null)
        {
            tv_title2.setText("");
        }else{
            tv_title2.setText(examItem);
        }
        //mill为你龙类型的时间戳
        if(lSubmitDate>0)
        {
            Date date=new Date(lSubmitDate);
            String submit="";
            try {
                //yyyy表示年MM表示月dd表示日
                //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                SimpleDateFormat sdf=new SimpleDateFormat("MM月dd日");
                //进行格式化
                submit=sdf.format(date);
            } catch (Exception e) {
                e.printStackTrace();
            }
            tv_date.setText(submit);
            tv_time.setText(submit);
        }else{
            tv_time.setText("");
            tv_date.setText("");
        }
     if(reformNo==0)
     {
         img_num.setVisibility(View.GONE);
     }else if(reformNo==1)
     {
         img_num.setVisibility(View.GONE);
     }else if(reformNo==2)
     {
         img_num.setVisibility(View.VISIBLE);
         img_num.setImageResource(R.mipmap.two_gai);
     }else if(reformNo==3)
     {
         img_num.setVisibility(View.VISIBLE);
         img_num.setImageResource(R.mipmap.three_gai);
     }else if(reformNo>=4)
     {
         img_num.setVisibility(View.VISIBLE);
         img_num.setImageResource(R.mipmap.four_gai);
     }

  if(lastRMark==0)
  {
      tv_title6.setTextColor(Color.parseColor("#FFCA5E"));
      tv_title6.setText("待整改");
      img_middle.setImageResource(R.mipmap.daitrough);
  }else if(lastRMark==1)
  {
      tv_title6.setTextColor(Color.parseColor("#007EFF"));
      tv_title6.setText("整改完成");
      img_middle.setImageResource(R.mipmap.trough);
  }
  if(lastCMark==0)
  {
      tv_title7.setTextColor(Color.parseColor("#FFCA5E"));
      tv_title7.setText("待审核");
      img_endline.setImageResource(R.mipmap.blue_line);
      img_end.setImageResource(R.mipmap.daitrough);
  }else if(lastCMark==1)
  {
      tv_title7.setTextColor(Color.parseColor("#007EFF"));
      tv_title7.setText("审核通过");
      img_endline.setImageResource(R.mipmap.blue_line);
      img_end.setImageResource(R.mipmap.trough);
  }else if(lastCMark==2)
  {
      tv_title7.setTextColor(Color.parseColor("#C7C7C7"));
      tv_title7.setText("审核不通过");
      img_endline.setImageResource(R.mipmap.gay_line);
      img_end.setImageResource(R.mipmap.notrough);
  }
        //mill为你龙类型的时间戳
        if(lastRDate>0)
        {
            Date date=new Date(lastRDate);
            String lastRDatestr="";
            try {
                //yyyy表示年MM表示月dd表示日
                //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                SimpleDateFormat sdf=new SimpleDateFormat("MM月dd日");
                //进行格式化
                lastRDatestr=sdf.format(date);
            } catch (Exception e) {
                e.printStackTrace();
            }

            tv_time1.setText(lastRDatestr);
        }else{
            tv_time1.setText("");

        }
        //mill为你龙类型的时间戳
        if(lastCDate>0)
        {
            Date date=new Date(lastCDate);
            String lastCDatestr="";
            try {
                //yyyy表示年MM表示月dd表示日
                //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                SimpleDateFormat sdf=new SimpleDateFormat("MM月dd日");
                //进行格式化
                lastCDatestr=sdf.format(date);
            } catch (Exception e) {
                e.printStackTrace();
            }

            tv_time2.setText(lastCDatestr);
        }else{
            tv_time2.setText("");

        }
    }


}